package com.mobi.Survey.controller;

import android.content.Context;

import com.mobi.Survey.model.AbstractTable;
import com.mobi.Survey.model.SubscriptionTable;

/**
 * 
 * <b>Author:</b> Yahya Arshad
 * <p>
 * <b>Company:</b> Mobi Media Soft
 * <p>
 * <b> Website:</b> www.mobimediasoft.com
 * <p>
 * SubscriptionPojo.java This class holds Survey's subscription detail
 */
public class SubscriptionPojo extends Pojo {
	private int id;
	private long subsId;
	private String fName = "fname";
	private String lName = "lname";
	private String email = "email";

	public int getId() {
		return id;
	}

	public long getSubsId() {
		return subsId;
	}

	public String getfName() {
		return fName;
	}

	public String getlName() {
		return lName;
	}

	public String getEmail() {
		return email;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setSubsId(long subsId) {
		this.subsId = subsId;
	}

	public void setfName(String fName) {
		this.fName = fName;
	}

	public void setlName(String lName) {
		this.lName = lName;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * 
	 * @param context
	 * @return if subscription data already exist in database or not
	 */
	public boolean isNew(Context context) {
		boolean is = false;

		SubscriptionTable at = new SubscriptionTable(context);
		try {
			is = at.isNewSubscription(subsId);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (at != null) {
				at.closeDB();
				at = null;
			}

		}
		return is;

	}

	/**
	 * 
	 * @param ctx
	 * @param sp
	 *            SubscripitonPojo to save
	 * @return true if success
	 */
	public static boolean commit(Context ctx, SubscriptionPojo sp) {
		AbstractTable at = new SubscriptionTable(ctx);
		boolean is = false;
		if (sp != null && sp.isNew(ctx)) {
			try {
				if (at.insertRow(sp) > 0) {
					is = true;
					printConsoleMsg(" SubscriptionPojo Class: Subscription Row Added ");
				} else {
					printConsoleMsg(" SubscriptionPojo Class: Duplicate Row ");
				}

			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				if (at != null)
					at.closeDB();
			}
		}
		return is;

	}

}
